home *** CD-ROM | disk | FTP | other *** search
/ Aminet 33 / Aminet 33 - October 1999.iso / Aminet / util / misc / resetserver.lha / ResetServer / ResetServerEmu / ResetServerEmu.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-07-31  |  36.8 KB  |  1,328 lines

  1. /* Reset.server emulator (c) 1997 Paweî Marciniak <pmarciniak@lodz.home.pl>*/
  2. /* Wersja finaîowa Niedziela 12-Kwi-98    13:11:00 */
  3. /* róûne poprawki Niedziela 20-Wrz-98    19:13:19 */
  4. /* róûne poprawki Niedziela 14-Lut-98    18:14:19 */
  5.       
  6. #include <stdio.h>
  7. #include <string.h>
  8. #include <exec/execbase.h>
  9. #include <exec/types.h>
  10. #include <exec/io.h>
  11. #include <exec/memory.h>
  12. #include <devices/serial.h>
  13. #include <intuition/intuition.h>
  14. #include <intuition/gadgetclass.h>
  15. #include <libraries/gadtools.h>
  16. #include <graphics/text.h>
  17. #include <graphics/gfxbase.h>
  18. #include <workbench/startup.h>
  19. #include <workbench/workbench.h>
  20. #include <proto/dos.h>
  21. #include <proto/exec.h>
  22. #include <proto/intuition.h>
  23. #include <proto/graphics.h>
  24. #include <proto/gadtools.h>
  25. #include <proto/diskfont.h>
  26. #include <proto/dos.h>
  27. #include <proto/icon.h>
  28. #include <stdlib.h>
  29.  
  30. #include <proto/image.h>
  31. #include <libraries/image.h>
  32.  
  33. #include <gadgets/tabs.h>
  34.  
  35. #include "ResetServer_globals.h"
  36. #include "ResetServer.h"
  37.  
  38. #include    "ResetServer_rev.h"
  39.  
  40. #define    LineDraw(x,y,x2,y2)    Move( APP_Window->RPort, x , y); \
  41.         Draw( APP_Window->RPort, x2, y2 )
  42.  
  43. static    UBYTE    verstr[]={ VERSTAG };
  44.  
  45. char __stdiowin[]="CON:10/10/600/240/Reset.server emulator/CLOSE/WAIT/AUTO";
  46.  
  47. extern struct ExecBase *SysBase;
  48.  
  49. struct MsgPort *serverport;
  50. struct SignalSemaphore sem;
  51.  
  52. ULONG sig=0L, sigwin=0L, sigmsg=0L;
  53.  
  54. BYTE path[1024], header[256], prtdev[108];
  55. ULONG prtunit=0;
  56.  
  57. /* Tytaj zaczynajâ sië wszystkie poûyteczne funkcje */
  58.  
  59. /* Funkcja dodaje tekst do listy historylist */
  60. int AddHistory( struct List *historylist, STRPTR text )
  61. {
  62.   struct Node *node;
  63.   STRPTR safetext;
  64.   if(!( safetext=AllocVec( (strlen(text)+1), MEMF_PUBLIC )))
  65.   {
  66.     return( FALSE );
  67.   }
  68.   strcpy( safetext, text );
  69.   if(!( node=AllocVec( sizeof(struct Node), MEMF_PUBLIC|MEMF_CLEAR )))
  70.   {
  71.     FreeVec( safetext );
  72.     return( FALSE );
  73.   }
  74.   node->ln_Name = safetext;
  75.   ObtainSemaphore( &sem );
  76.   AddTail( historylist, node );
  77.   ReleaseSemaphore( &sem );
  78.   return( TRUE );
  79. }
  80.  
  81. /* Funkcja czyôci historylist */
  82. void RemHistory( struct List *historylist )
  83. {
  84.   struct Node *node;
  85.  
  86.   ObtainSemaphore( &sem );
  87.   for( node=historylist->lh_Head; node->ln_Succ; node=historylist->lh_Head )
  88.   {
  89.     Remove( node );
  90.     FreeVec( node->ln_Name );
  91.     FreeVec( node );
  92.   }
  93.   ReleaseSemaphore( &sem );
  94.  
  95. }
  96.  
  97.  
  98. /* Funkcje Reset.server */
  99. void SendWarning( struct List *portlist )
  100. {
  101.   struct RWNode *node;
  102.   struct RWMessage *WarnMsg;
  103.  
  104.   ObtainSemaphore( &sem );
  105.   for( node=(struct RWNode *)portlist->lh_Head; node->rwn_Node.ln_Succ; node=(struct RWNode *)node->rwn_Node.ln_Succ )
  106.   {
  107.     if(node->rwn_MsgPort)
  108.     {
  109.           WarnMsg=(struct RWMessage *)AllocVec( sizeof(struct RWMessage), MEMF_PUBLIC|MEMF_CLEAR );
  110.           WarnMsg->rwm_Message.mn_ReplyPort=serverport;
  111.           WarnMsg->rwm_MsgType=RWM_RESETWARNING;
  112.       PutMsg( node->rwn_MsgPort, (struct Message *)WarnMsg);
  113.     }
  114.   }
  115.   ReleaseSemaphore( &sem );
  116. }
  117.  
  118. /* Funkcja dodaje msgport do listy portlist */
  119. int RW_AddPort( struct List *portlist, struct RWMessage *rwmsg )
  120. {
  121.   struct RWNode *node;
  122.  
  123.   if( node=(struct RWNode *)AllocVec( sizeof(struct RWNode), MEMF_PUBLIC|MEMF_CLEAR ) )
  124.   {
  125.     node->rwn_MsgPort = rwmsg->rwm_MsgPort;
  126.     node->rwn_ProgName = rwmsg->rwm_ProgName;
  127.     node->rwn_Node.ln_Name = rwmsg->rwm_ProgName;
  128.     ObtainSemaphore( &sem );
  129.     AddTail( portlist, (struct Node *)node );
  130.     ReleaseSemaphore( &sem );
  131.     return( TRUE );
  132.   }
  133.   return( FALSE );
  134. }
  135.  
  136. /* Funkcja usuwa msgport z listy portlist */
  137. void RW_RemPort( struct List *portlist, struct RWMessage *rwmsg )
  138. {
  139.   struct RWNode *node;
  140.  
  141.   ObtainSemaphore( &sem );
  142.   for( node=(struct RWNode *)portlist->lh_Head; node->rwn_Node.ln_Succ; node=(struct RWNode *)node->rwn_Node.ln_Succ )
  143.   {
  144.     if(node->rwn_MsgPort==rwmsg->rwm_MsgPort)
  145.     {
  146.       Remove( (struct Node *)node );
  147.       FreeVec( node );
  148.       break;
  149.     }
  150.   }
  151.   ReleaseSemaphore( &sem );
  152. }
  153.  
  154. /* Busy Win */
  155. BOOL BusyStart( struct Window *win, struct Requester *waitRequest )
  156. {
  157.   InitRequester( waitRequest );
  158.   if( Request( waitRequest, win ))
  159.   {
  160.     SetWindowPointer( win, WA_BusyPointer, TRUE, TAG_DONE );
  161.     return( TRUE );
  162.   }
  163.   else
  164.     return( FALSE );
  165. }
  166.  
  167. VOID BusyEnd( struct Window *win, struct Requester *waitRequest )
  168. {
  169.   ClearPointer( win );
  170.   EndRequest( waitRequest, win );
  171. }
  172.  
  173.  
  174. /* Funkcja zapisuje historylist do pliku */
  175. LONG WriteHistory( STRPTR filename, STRPTR header, struct List *historylist )
  176. {
  177.   BPTR fh;
  178.   struct Node *node;
  179.   struct Requester busyreq;
  180.     BOOL busy=FALSE;
  181.  
  182.   busy=BusyStart( APP_Window, &busyreq );
  183.  
  184.   if(!( fh=Open( filename, MODE_READWRITE )))
  185.     {
  186.         if( busy ) BusyEnd( APP_Window, &busyreq );
  187.     return( FALSE );
  188.     }
  189.   Seek( fh, 0, OFFSET_END );
  190.  
  191.   if((Write( fh, header, strlen( header ))) == -1)
  192.   {
  193.     Close( fh );
  194.       if( busy ) BusyEnd( APP_Window, &busyreq );
  195.     return( FALSE );
  196.   }
  197.  
  198.     ObtainSemaphore( &sem );
  199.   for( node=historylist->lh_Head; node->ln_Succ; node=node->ln_Succ )
  200.   {
  201.     if((Write( fh, node->ln_Name, strlen( node->ln_Name ))) == -1)
  202.     {
  203.       Close( fh );
  204.         if( busy ) BusyEnd( APP_Window, &busyreq );
  205.         ReleaseSemaphore( &sem );
  206.       return( FALSE );
  207.     }
  208.  
  209.     if((Write( fh, "\n", 1 )) == -1)
  210.     {
  211.       Close( fh );
  212.         if( busy ) BusyEnd( APP_Window, &busyreq );
  213.         ReleaseSemaphore( &sem );
  214.       return( FALSE );
  215.     }
  216.   }
  217.   ReleaseSemaphore( &sem );
  218.   Close( fh );
  219.   if( busy ) BusyEnd( APP_Window, &busyreq );
  220.   return( TRUE );
  221. }
  222.  
  223. LONG PrintHistory( STRPTR devicename, ULONG deviceunit, struct List *historylist )
  224. {
  225.     struct MsgPort *ioport=NULL;
  226.     struct IOStdReq *ioreq=NULL;
  227.     struct Node *node;
  228.  
  229.     if (!(ioport=CreatePort( NULL, 0L )))
  230.         return( 1 );    
  231.     if (!(ioreq=CreateIORequest( ioport, sizeof(struct IOStdReq))))
  232.     {
  233.         DeletePort ( ioport );
  234.         return( 2 );
  235.     }
  236.     if (OpenDevice( devicename, deviceunit, (struct IORequest *)ioreq, 0L ))
  237.     {
  238.         DeleteIORequest( ioreq );
  239.         DeletePort ( ioport );
  240.         return( 3 );
  241.     }
  242.  
  243.     ObtainSemaphore( &sem );
  244.   for( node=historylist->lh_Head; node->ln_Succ; node=node->ln_Succ )
  245.   {
  246.         ioreq->io_Command=CMD_WRITE;
  247.         ioreq->io_Data=(APTR)node->ln_Name;
  248.         ioreq->io_Length=-1;
  249.         if (DoIO ((struct IORequest *)ioreq))
  250.         {
  251.             ReleaseSemaphore( &sem );
  252.             CloseDevice( (struct IORequest *)ioreq );
  253.             DeleteIORequest( ioreq );
  254.             DeletePort ( ioport );
  255.             return( 4 );
  256.         }
  257.     ioreq->io_Command=CMD_WRITE;
  258.         ioreq->io_Data=(APTR)"\n";
  259.         ioreq->io_Length=-1;
  260.         if (DoIO ((struct IORequest *)ioreq))
  261.         {
  262.             ReleaseSemaphore( &sem );
  263.             CloseDevice( (struct IORequest *)ioreq );
  264.             DeleteIORequest( ioreq );
  265.             DeletePort ( ioport );
  266.             return( 4 );
  267.         }
  268.     }
  269.     ReleaseSemaphore( &sem );
  270.  
  271.     CloseDevice( (struct IORequest *)ioreq );
  272.     DeleteIORequest( ioreq );
  273.     DeletePort ( ioport );
  274.     return( 0 );
  275. }
  276.  
  277.  
  278. struct ClassLibrary *openclass (STRPTR name, ULONG version)
  279. {
  280.     struct Library *retval;
  281.     UBYTE buffer[256];
  282.  
  283.     if ((retval = OpenLibrary (name, version)) == NULL)
  284.     {
  285.     sprintf (buffer, ":classes/%s", name);
  286.     if ((retval = OpenLibrary (buffer, version)) == NULL)
  287.     {
  288.         sprintf (buffer, "classes/%s", name);
  289.         retval = OpenLibrary (buffer, version);
  290.     }
  291.     }
  292.     return (struct ClassLibrary *) retval;
  293. }
  294.  
  295. LONG MakeTab( void )
  296. {
  297.     if(TabBase = openclass ("gadgets/tabs.gadget", 42))
  298.     {
  299.         if(gad_tab = NewObject (NULL, "tabs.gadget",
  300.                     GA_Top,            APP_Window->BorderTop + 2,
  301.                     GA_Left,        APP_Window->BorderLeft,
  302.                     GA_Height,      FontY + 5,
  303.                     GA_RelWidth,    -(APP_Window->BorderLeft + APP_Window->BorderRight),
  304.                     GA_TextAttr,    &ScreenFont,
  305.                     GA_RelVerify,    TRUE,
  306.                     GA_Immediate,    TRUE,
  307.                     GA_ID,        GD_TAB,
  308.           LAYOUTA_ChildMaxWidth, FALSE,
  309.                     TABS_Labels,    labels,
  310.                     TABS_Current,    0,
  311.                     TAG_DONE))
  312.         {
  313.       return( TRUE );
  314.     }
  315.   }
  316.   return( FALSE );
  317. }
  318.  
  319.  
  320. int MakeGadget( struct List *historylist, struct List *portlist )
  321. {
  322.   if ( g = CreateContext( &APP_GList ))
  323.   {
  324. /* ResetWarning */
  325.     ng.ng_TopEdge    =  (ComputeY( 18 ) + OffY );
  326.     ng.ng_LeftEdge  =  ComputeX( 10 ) + OffX;
  327.     ng.ng_Width      =  ComputeX( 150 );
  328.     ng.ng_Height    =  ComputeY( 12 );
  329.     ng.ng_TextAttr    =  &ScreenFont;
  330.     ng.ng_GadgetText=  MSG_GAD_WARNING;
  331.     ng.ng_GadgetID  =  GD_WARNING;
  332.     ng.ng_Flags       =  PLACETEXT_IN;
  333.     ng.ng_VisualInfo  =  VisualInfo;
  334.     ng.ng_UserData    =  NULL;
  335.     if(!(gad_button = g = CreateGadget( BUTTON_KIND, g, &ng, GT_Underscore, '_', GA_Disabled, TRUE, TAG_DONE )))
  336.       return( FALSE );
  337.  
  338. /* Text komunikaty */
  339.     ng.ng_TopEdge    =  (ComputeY( 18 ) + OffY);
  340.     ng.ng_LeftEdge  =  ComputeX( 170) + OffX;
  341.     ng.ng_Width      =  ComputeX( 320 );
  342.     ng.ng_Height    =  ComputeY( 12 );
  343.     ng.ng_GadgetText=  "";
  344.     ng.ng_GadgetID  =  GD_TEXT;
  345.     if(!(gad_text = g = CreateGadget( TEXT_KIND, g, &ng, GTTX_Text, (ULONG)"",
  346.                                                    GTTX_Justification, GTJ_LEFT,
  347.                                                    GTTX_Border, TRUE,
  348.                                                    TAG_DONE )))
  349.       return( FALSE );
  350.  
  351. /* nazwy programów */
  352.     ng.ng_TopEdge    =  ComputeY( 41 ) + OffY;
  353.     ng.ng_LeftEdge  =  ComputeX( 10 ) + OffX;
  354.     ng.ng_Width      =  ComputeX( 150 );
  355.     ng.ng_Height    =  ComputeY( 68 );
  356.     ng.ng_Flags       =  PLACETEXT_ABOVE | NG_HIGHLABEL;
  357.     ng.ng_GadgetText=  NULL;
  358.     ng.ng_GadgetID  =  GD_LVIEW;
  359.     if(!(gad_pname = g = CreateGadget( LISTVIEW_KIND, g, &ng, GTLV_Labels, portlist,
  360.                                    GTLV_ReadOnly, TRUE,
  361.                                    TAG_DONE )))
  362.       return( FALSE );
  363.  
  364. /* Historia */
  365.     ng.ng_TopEdge    =  ComputeY( 41 ) + OffY;
  366.     ng.ng_LeftEdge  =  ComputeX( 175 ) + OffX;
  367.     ng.ng_Width      =  ComputeX( 315 );
  368.     ng.ng_Height    =  ComputeY( 68 );
  369.     ng.ng_GadgetText=  NULL;
  370.     ng.ng_GadgetID  =  GD_HIST;
  371.     if(!(gad_hist = g = CreateGadget( LISTVIEW_KIND, g, &ng, GTLV_Labels, historylist,
  372.                                    GTLV_ReadOnly, TRUE,
  373.                                    TAG_DONE )))
  374.       return( FALSE );
  375.     return( TRUE );
  376.   }
  377. return( FALSE );
  378. }
  379.  
  380. int MakeGadget2( STRPTR path, STRPTR header, int wborcli )
  381. {
  382.   if ( g = CreateContext( &APP_GList2 ))
  383.   {
  384. /* Path */
  385.     ng.ng_TopEdge    =  (ComputeY( 25 ) + OffY );
  386.     ng.ng_LeftEdge  =  ComputeX( 155 ) + OffX;
  387.     ng.ng_Width      =  ComputeX( 330 );
  388.     ng.ng_Height    =  ComputeY( 12 );
  389.     ng.ng_TextAttr    =  &ScreenFont;
  390.     ng.ng_GadgetText=  MSG_GAD_PATH;
  391.     ng.ng_GadgetID  =  GD_PATH;
  392.     ng.ng_Flags       =  PLACETEXT_LEFT;
  393.     ng.ng_VisualInfo  =  VisualInfo;
  394.     ng.ng_UserData    =  NULL;
  395.     if(!(gad_path = g = CreateGadget( STRING_KIND, g, &ng, GT_Underscore, '_', GTST_String, path, GTST_MaxChars, 256, TAG_DONE )))
  396.       return( FALSE );
  397.  
  398. /* Header */
  399.     ng.ng_TopEdge    =  (ComputeY( 40 ) + OffY );
  400.     ng.ng_LeftEdge  =  ComputeX( 155 ) + OffX;
  401.     ng.ng_Width      =  ComputeX( 330 );
  402.     ng.ng_Height    =  ComputeY( 12 );
  403.     ng.ng_GadgetText=  MSG_GAD_HEADER;
  404.     ng.ng_GadgetID  =  GD_HEADER;
  405.     ng.ng_Flags       =  PLACETEXT_LEFT;
  406.     ng.ng_UserData    =  NULL;
  407.     if(!(gad_header = g = CreateGadget( STRING_KIND, g, &ng, GT_Underscore, '_', GTST_String, header, GTST_MaxChars, 256, TAG_DONE )))
  408.       return( FALSE );
  409.  
  410. /* prtdev */
  411.     ng.ng_TopEdge    =  (ComputeY( 70 ) + OffY );
  412.     ng.ng_LeftEdge  =  ComputeX( 155 ) + OffX;
  413.     ng.ng_Width      =  ComputeX( 195 );
  414.     ng.ng_Height    =  ComputeY( 12 );
  415.     ng.ng_GadgetText=  MSG_GAD_PRTDEV;
  416.     ng.ng_GadgetID  =  GD_PRTDEV;
  417.     ng.ng_Flags       =  PLACETEXT_LEFT;
  418.     ng.ng_UserData    =  NULL;
  419.     if(!(gad_prtdev = g = CreateGadget( STRING_KIND, g, &ng, GT_Underscore, '_', GTST_String, prtdev, GTST_MaxChars, 108, TAG_DONE )))
  420.       return( FALSE );
  421.  
  422. /* prtunit */
  423.     ng.ng_TopEdge    =  (ComputeY( 70 ) + OffY );
  424.     ng.ng_LeftEdge  =  ComputeX( 450 ) + OffX;
  425.     ng.ng_Width      =  ComputeX( 35 );
  426.     ng.ng_Height    =  ComputeY( 12 );
  427.     ng.ng_GadgetText=  MSG_GAD_PRTUNIT;
  428.     ng.ng_GadgetID  =  GD_PRTUNIT;
  429.     ng.ng_Flags       =  PLACETEXT_LEFT;
  430.     ng.ng_UserData    =  NULL;
  431.     if(!(gad_prtunit = g = CreateGadget( INTEGER_KIND, g, &ng, GT_Underscore, '_', GTIN_Number, prtunit, TAG_DONE )))
  432.       return( FALSE );
  433.  
  434. /* Save  */
  435.     ng.ng_TopEdge    =  (ComputeY( 96 ) + OffY );
  436.     ng.ng_LeftEdge  =  ComputeX( 10 ) + OffX;
  437.     ng.ng_Width      =  ComputeX( 120 );
  438.     ng.ng_Height    =  ComputeY( 12 );
  439.     ng.ng_GadgetText=  MSG_GAD_SAVE;
  440.     ng.ng_GadgetID  =  GD_SAVE;
  441.     ng.ng_Flags       =  PLACETEXT_IN;
  442.     ng.ng_UserData    =  NULL;
  443.     if(!(gad_save = g = CreateGadget( BUTTON_KIND, g, &ng, GT_Underscore, '_', GA_Disabled, wborcli ? TRUE : FALSE, TAG_DONE )))
  444.       return( FALSE );
  445.  
  446. /* Use  */
  447.     ng.ng_TopEdge    =  (ComputeY( 96 ) + OffY );
  448.     ng.ng_LeftEdge  =  ComputeX( 190 ) + OffX;
  449.     ng.ng_Width      =  ComputeX( 120 );
  450.     ng.ng_Height    =  ComputeY( 12 );
  451.     ng.ng_GadgetText=  MSG_GAD_USE;
  452.     ng.ng_GadgetID  =  GD_USE;
  453.     ng.ng_Flags       =  PLACETEXT_IN;
  454.     ng.ng_UserData    =  NULL;
  455.     if(!(gad_use = g = CreateGadget( BUTTON_KIND, g, &ng, GT_Underscore, '_', TAG_DONE )))
  456.       return( FALSE );
  457.  
  458. /* UnDo  */
  459.     ng.ng_TopEdge    =  (ComputeY( 96 ) + OffY );
  460.     ng.ng_LeftEdge  =  ComputeX( 365 ) + OffX;
  461.     ng.ng_Width      =  ComputeX( 120 );
  462.     ng.ng_Height    =  ComputeY( 12 );
  463.     ng.ng_GadgetText=  MSG_GAD_UNDO;
  464.     ng.ng_GadgetID  =  GD_UNDO;
  465.     ng.ng_Flags       =  PLACETEXT_IN;
  466.     ng.ng_UserData    =  NULL;
  467.     if(!(gad_undo = g = CreateGadget( BUTTON_KIND, g, &ng, GT_Underscore, '_', TAG_DONE )))
  468.       return( FALSE );
  469.     return( TRUE );
  470.   }
  471. return( FALSE );
  472. }
  473.  
  474. void DrawGadsBox( void )
  475. {
  476.     Draw3DBox( APP_Window->RPort, APP_Font,
  477.                         DBA_PosX,        ComputeX( 5 ) + OffX,
  478.                         DBA_PosY,        ComputeY( 36 ) + OffY,
  479.                         DBA_Width,    ComputeX( 160 ),
  480.                         DBA_Height,    ComputeY( 75 ),
  481.                         DBA_Text,        MSG_GAD_PNAME,
  482.             DBA_Align,  ALIGN_CENTER,
  483.                         TAG_DONE );
  484.  
  485.     Draw3DBox( APP_Window->RPort, APP_Font,
  486.                         DBA_PosX,        ComputeX( 170 ) + OffX,
  487.                         DBA_PosY,        ComputeY( 36 ) + OffY,
  488.                         DBA_Width,    ComputeX( 325 ),
  489.                         DBA_Height,    ComputeY( 75 ),
  490.                         DBA_Text,        MSG_GAD_HIST,
  491.             DBA_Align,  ALIGN_CENTER,
  492.                         TAG_DONE );
  493.   SetAPen( APP_Window->RPort, 0 );
  494. }
  495.  
  496. void DrawGadsBox2( void )
  497. {
  498.     Draw3DBox( APP_Window->RPort, APP_Font,
  499.                         DBA_PosX,        ComputeX( 5 ) + OffX,
  500.                         DBA_PosY,        ComputeY( 20 ) + OffY,
  501.                         DBA_Width,    ComputeX( 490 ),
  502.                         DBA_Height,    ComputeY( 35 ),
  503.                         DBA_Text,        MSG_TXT_FILEPREF,
  504.             DBA_Align,  ALIGN_LEFT,
  505.                         TAG_DONE );
  506.  
  507.     Draw3DBox( APP_Window->RPort, APP_Font,
  508.                         DBA_PosX,        ComputeX( 5 ) + OffX,
  509.                         DBA_PosY,        ComputeY( 65 ) + OffY,
  510.                         DBA_Width,    ComputeX( 490 ),
  511.                         DBA_Height,    ComputeY( 20 ),
  512.                         DBA_Text,        MSG_TXT_PRTPREF,
  513.             DBA_Align,  ALIGN_LEFT,
  514.                         TAG_DONE );
  515.   SetAPen( APP_Window->RPort, 0 );
  516. }
  517.  
  518. int OpenFonts( void )
  519. {
  520.   if (!(APP_Font=OpenDiskFont( &ScreenFont )))
  521.     return( FALSE );
  522.   return( TRUE );
  523. }
  524.  
  525.  
  526. /* Funkcja zamyka otwarty font */
  527.  
  528. void CloseFonts( void )
  529. {
  530.   if ( APP_Font )  
  531.   {
  532.     CloseFont( APP_Font );
  533.     APP_Font=NULL;
  534.   }
  535. }
  536.  
  537.  
  538. UWORD ComputeX( UWORD value )
  539. {
  540.   return(( UWORD )((( FontX * value ) + 4 ) / 8 ));
  541. }
  542.  
  543.  
  544. UWORD ComputeY( UWORD value )
  545. {
  546.   return(( UWORD )((( FontY * value ) + 4 ) / 8 ));
  547. }
  548.  
  549.  
  550. void ComputeFont( void )
  551. {
  552.   Font = &ScreenFont;
  553.   Font->ta_Name = (STRPTR)Screen->RastPort.Font->tf_Message.mn_Node.ln_Name;
  554.   Font->ta_YSize = FontY = Screen->RastPort.Font->tf_YSize;
  555.   FontX = Screen->RastPort.Font->tf_XSize;
  556.   OffX = Screen->WBorLeft;
  557.   OffY = Screen->RastPort.TxHeight + Screen->WBorTop + 1;
  558.   return;
  559. }
  560.  
  561.  
  562. /* Funkcja otwiera okno */
  563.  
  564. int OpenAPP_Display( WORD Left, WORD Top )
  565. {
  566.   WORD Width=500;
  567.   WORD Height=114;
  568.  
  569.   if(!(APP_Window=OpenWindowTags( 0,
  570.     WA_Left,        Left,
  571.     WA_Top,          Top,
  572.     WA_Width,        ComputeX(Width) + OffX + Screen->WBorRight,
  573.     WA_Height,      ComputeY(Height) + OffY + Screen->WBorBottom,
  574.     WA_Activate,    TRUE,
  575.     WA_NewLookMenus,TRUE,
  576.     WA_Title,        APP_TitleWindow,
  577.     WA_Flags,        WFLG_DRAGBAR | WFLG_DEPTHGADGET | WFLG_CLOSEGADGET | WFLG_SMART_REFRESH,
  578.     WA_IDCMP,        IDCMP_CLOSEWINDOW | IDCMP_MENUPICK | IDCMP_REFRESHWINDOW | IDCMP_GADGETUP | LISTVIEWIDCMP | IDCMP_VANILLAKEY,
  579.     WA_Gadgets,      NULL,
  580.     WA_AutoAdjust,  FALSE,
  581.     WA_PubScreen,    (struct Screen *)Screen,
  582.     TAG_DONE)))
  583.       return( FALSE );
  584.   GT_RefreshWindow( APP_Window, NULL );
  585.   sigwin=( 1L << APP_Window->UserPort->mp_SigBit );
  586.   return( TRUE );
  587. }
  588.  
  589.  
  590. /* Funkcja odczytuje komunikat Intuition */
  591.  
  592. LONG ReadIMsg( struct Window *iwnd )
  593. {
  594.   struct IntuiMessage *imsg;
  595.   
  596.   if ( imsg = GT_GetIMsg( iwnd->UserPort ))
  597.   {
  598.     IClass    =  imsg->Class;
  599.     Qualifier  =  imsg->Qualifier;
  600.     Code      =  imsg->Code;
  601.     IObject    =  imsg->IAddress;
  602.  
  603.     GT_ReplyIMsg( imsg );
  604.     return( TRUE );
  605.   }
  606.   return( FALSE );
  607. }
  608.  
  609.  
  610. /* Funkcja zamyka otwarte okno */
  611.  
  612. void CloseAPP_Display(void)
  613. {
  614.   if(APP_Window) 
  615.   {
  616.     Forbid();
  617.     while ( ReadIMsg( APP_Window ))
  618.     ;
  619.     CloseWindow((struct Window *)APP_Window);
  620.     APP_Window=NULL;
  621.     Permit();
  622.   }
  623. }
  624.  
  625.  
  626. /* Funkcja alokuje ekran */
  627.  
  628. int SetupScreen( void )
  629. {
  630.   if (!(Screen = LockPubScreen( PubScreenName )))
  631.     return( FALSE );
  632.  
  633.   ComputeFont();
  634.  
  635.   if(!(OpenFonts()))
  636.     return( FALSE );
  637.  
  638.  
  639.   if (!( VisualInfo = GetVisualInfo( Screen, TAG_DONE )))
  640.     return( FALSE );
  641.  
  642.   return( TRUE );
  643. }
  644.  
  645.  
  646. /* Funkcja dealokuje ekran */
  647.  
  648. void CloseDownScreen( void )
  649. {
  650.   if ( VisualInfo )
  651.   {
  652.     FreeVisualInfo( VisualInfo );
  653.     VisualInfo = NULL;
  654.   }
  655.  
  656.   CloseFonts();
  657.  
  658.   if ( Screen )
  659.   {
  660.     UnlockPubScreen( NULL, Screen );
  661.     Screen = NULL;
  662.   }
  663. }
  664.  
  665. BOOL OpenMenu( void )
  666. {
  667.   if(!(MenuStrip=CreateMenus( mbld,TAG_DONE )))
  668.     return( FALSE );
  669.   LayoutMenus( MenuStrip, VisualInfo, GTMN_NewLookMenus, TRUE, TAG_DONE );
  670.   SetMenuStrip( APP_Window, MenuStrip );
  671.   return( TRUE );
  672. }
  673.  
  674. void CloseMenu( void )
  675. {
  676.   ClearMenuStrip( APP_Window );
  677.   if( MenuStrip )
  678.   {
  679.     FreeMenus( MenuStrip );
  680.     MenuStrip=NULL;
  681.   }
  682. }
  683.  
  684.  
  685. /* Funkcja otwiera wszystkie biblioteki */
  686.  
  687. LONG OpenLibraries( void )
  688. {
  689.   if ( !(DosBase = (struct DosLibrary *) OpenLibrary((UBYTE *) "dos.library", 37 )))
  690.     return( FALSE );
  691.   if ( !(IntuitionBase = (struct IntuitionBase *) OpenLibrary((UBYTE *) "intuition.library", 37 )))
  692.     return( FALSE );
  693.   if ( !(GadToolsBase = (struct Library *) OpenLibrary((UBYTE *) "gadtools.library", 39 )))
  694.     return( FALSE );
  695.   if ( !(GfxBase = (struct GfxBase *) OpenLibrary((UBYTE *) "graphics.library" , 37 )))
  696.     return( FALSE );
  697.   if ( !(DiskFontBase = (struct Library *) OpenLibrary((UBYTE *) "diskfont.library" , 37 )))
  698.     return( FALSE );
  699.   if ( !(IconBase = (struct Library *) OpenLibrary((UBYTE *) "icon.library" , 37 )))
  700.     return( FALSE );
  701.     if ( !(ImageBase = (struct Library *) OpenLibrary((UBYTE *) "image.library" , 36 )))
  702.     {
  703.         printf("Couldn't open image.library\n");
  704.         return( FALSE );
  705.     }
  706.  
  707.   return( TRUE );
  708. }
  709.  
  710.  
  711. /* Funkcja zamyka wszystkie biblioteki */
  712.  
  713. void CloseLibraries( void )
  714. {
  715.     if (ImageBase)            CloseLibrary( (struct Library *) ImageBase );
  716.   if (DiskFontBase)   CloseLibrary( (struct Library *) DiskFontBase );
  717.   if (IconBase)            CloseLibrary( (struct Library *) IconBase );
  718.   if (GfxBase)        CloseLibrary( (struct Library *) GfxBase );
  719.   if (GadToolsBase)   CloseLibrary( (struct Library *) GadToolsBase );
  720.   if (IntuitionBase)  CloseLibrary( (struct Library *) IntuitionBase );
  721.   if (DosBase)        CloseLibrary( (struct Library *) DOSBase );
  722. }
  723.  
  724.  
  725. void ShutDown( void )
  726. {
  727.   if (serverport)
  728.     DeletePort (serverport);
  729.   if(gad_tab)
  730.   {
  731.       RemoveGadget( APP_Window, gad_tab );
  732.     DisposeObject (gad_tab);
  733.     gad_tab=NULL;
  734.   }
  735.   if(TabBase)
  736.   {
  737.     CloseLibrary ((struct Library *) TabBase);
  738.     TabBase=NULL;
  739.   }
  740.   CloseMenu();
  741.   CloseAPP_Display();
  742.   FreeGadgets( APP_GList2 );
  743.   APP_GList2 = NULL;
  744.   FreeGadgets( APP_GList );
  745.   APP_GList = NULL;
  746.   CloseDownScreen();
  747.   CloseLibraries();
  748. }
  749.  
  750. /* Funkcja obsîuguje rwmessage */
  751. void MessageFunc( STRPTR tab, STRPTR text, ULONG cases, struct RWMessage *msg, struct List *portlist, struct List *historylist, ULONG gad )
  752. {
  753. if(!gad)
  754. {
  755.     GT_SetGadgetAttrs( gad_hist, APP_Window, 0, GTLV_Labels, -1, TAG_DONE);
  756.     sprintf( tab, text, msg->rwm_ProgName, msg->rwm_MsgPort );
  757.     AddHistory( historylist, tab );
  758.     GT_SetGadgetAttrs( gad_hist, APP_Window, 0, GTLV_Labels, historylist, TAG_DONE);
  759.  
  760.     GT_SetGadgetAttrs( gad_pname, APP_Window, 0, GTLV_Labels, -1, TAG_DONE);
  761.     switch( cases )
  762.     {
  763.         case RWM_ADDPORT:
  764.             RW_AddPort( portlist, msg );
  765.         break;
  766.         case RWM_REMPORT:
  767.         case RWM_DONE:
  768.             RW_RemPort( portlist, msg );
  769.         break;
  770.     }
  771.     GT_SetGadgetAttrs( gad_pname, APP_Window, 0, GTLV_Labels, portlist, TAG_DONE);
  772.     GT_SetGadgetAttrs( gad_text, APP_Window, 0, GTTX_Text, (ULONG)"Message RWM_ADDPORT", TAG_DONE);
  773.     switch( cases )
  774.     {
  775.         case RWM_ADDPORT:
  776.         case RWM_REMPORT:
  777.             if( IsListEmpty( portlist ) )
  778.             GT_SetGadgetAttrs( gad_button, APP_Window, 0, GA_Disabled, TRUE, TAG_DONE);
  779.           else
  780.             GT_SetGadgetAttrs( gad_button, APP_Window, 0, GA_Disabled, FALSE, TAG_DONE);
  781.         break;
  782.         case RWM_DONE:
  783.             if( IsListEmpty( portlist ) )
  784.       {
  785.         GT_SetGadgetAttrs( gad_text, APP_Window, 0, GTTX_Text, (ULONG)"All ports done - Reset", TAG_DONE);
  786.         GT_SetGadgetAttrs( gad_button, APP_Window, 0, GA_Disabled, TRUE, TAG_DONE);
  787.       }
  788.         break;
  789.     }
  790. }
  791. else
  792. {
  793.     sprintf( tab, text, msg->rwm_ProgName, msg->rwm_MsgPort );
  794.     AddHistory( historylist, tab );
  795.     switch( cases )
  796.     {
  797.         case RWM_ADDPORT:
  798.             RW_AddPort( portlist, msg );
  799.         break;
  800.         case RWM_REMPORT:
  801.         case RWM_DONE:
  802.             RW_RemPort( portlist, msg );
  803.         break;
  804.     }
  805.     if( IsListEmpty( portlist ) )
  806.     gad_button->Flags|=GFLG_DISABLED;
  807.   else
  808.     gad_button->Flags&=~GFLG_DISABLED;
  809. }
  810.  
  811. }
  812.  
  813. /* Funkcja obsîuguje gadget gad_tab */
  814. void GadTabFunc( ULONG cases, ULONG tab )
  815. {
  816.     switch( cases )
  817.     {
  818.         case 0:
  819.             if(tab==1)    RemoveGList( APP_Window, APP_GList2, -1 );
  820.             RectFill( APP_Window->RPort, APP_Window->BorderLeft, APP_Window->BorderTop + FontY + 7,
  821.                       APP_Window->Width-(APP_Window->BorderRight)-1, ComputeY( 122 ));
  822.           AddGList( APP_Window, APP_GList, -1, -1, 0 );
  823.           RefreshGadgets( APP_GList, APP_Window, 0 );
  824.           GT_RefreshWindow( APP_Window, 0 );
  825.             DrawGadsBox();
  826.         break;
  827.  
  828.         case 1:
  829.             if(tab==0)    RemoveGList( APP_Window, APP_GList, -1 );
  830.             RectFill( APP_Window->RPort, APP_Window->BorderLeft, APP_Window->BorderTop + FontY + 7,
  831.                       APP_Window->Width-(APP_Window->BorderRight)-1, ComputeY( 122 ));
  832.           AddGList( APP_Window, APP_GList2, -1, -1, 0 );
  833.           RefreshGadgets( APP_GList2, APP_Window, 0 );
  834.           GT_RefreshWindow( APP_Window, 0 );
  835.       GT_SetGadgetAttrs( gad_path, APP_Window, 0, GTST_String, path, TAG_DONE);
  836.       GT_SetGadgetAttrs( gad_header, APP_Window, 0, GTST_String, header, TAG_DONE);
  837.       DrawGadsBox2();
  838.         break;
  839.  
  840.         case 2:
  841.         case 3:
  842.             if(tab==1)    RemoveGList( APP_Window, APP_GList2, -1 );
  843.             if(tab==0)    RemoveGList( APP_Window, APP_GList, -1 );
  844.             RectFill( APP_Window->RPort, APP_Window->BorderLeft, APP_Window->BorderTop + FontY + 7,
  845.                       APP_Window->Width-(APP_Window->BorderRight)-1, ComputeY( 122 ));
  846.         break;
  847.     }
  848. }
  849.  
  850. /* Funkcja wypisuje tekst */
  851. void DrawInfoText( STRPTR wintext )
  852. {
  853.     SetAPen( APP_Window->RPort, 1 );
  854.     DrawText( DT_Texts, wintext,
  855.                         DT_FontA, APP_Font,
  856.                         DT_FontB, APP_Font,
  857.                         DT_RastPort , APP_Window->RPort,
  858.                         DT_Top, APP_Window->BorderTop + FontY + 10,
  859.                         DT_Left, APP_Window->Width/2,
  860.                         TAG_DONE);
  861.     SetAPen( APP_Window->RPort, 0 );
  862. }
  863.  
  864. LONG EasyDialogBox( struct Window *edb_win, STRPTR edb_title, STRPTR edb_text, STRPTR edb_button, APTR edb_args )
  865. {
  866.     struct EasyStruct easyreq;
  867.     
  868.     easyreq.es_StructSize=sizeof(struct EasyStruct);
  869.     easyreq.es_Title=edb_title;
  870.     easyreq.es_TextFormat=edb_text;
  871.     easyreq.es_GadgetFormat=edb_button;
  872.     return(EasyRequestArgs( edb_win, &easyreq, 0, edb_args ));
  873. }
  874.  
  875. /* Funkcja odczytuje preferencje z ikony */
  876. LONG ReadPrefs( STRPTR prefs_path, STRPTR prefs_header, STRPTR icon_name )
  877. {
  878.     struct DiskObject *PrefsIcon;
  879.     STRPTR string;
  880.  
  881.     if(!(PrefsIcon=GetDiskObject( icon_name )))
  882.         return(1000);
  883.     if(string=FindToolType( PrefsIcon->do_ToolTypes, "PATH" ))
  884.         strcpy( prefs_path, string );
  885.     if(string=FindToolType( PrefsIcon->do_ToolTypes, "HEADER" ))
  886.         strcpy( prefs_header, string );
  887.     if(string=FindToolType( PrefsIcon->do_ToolTypes, "DEVICE" ))
  888.         strcpy( prtdev, string );
  889.     if(string=FindToolType( PrefsIcon->do_ToolTypes, "UNIT" ))
  890.         prtunit=atol( string );
  891.     FreeDiskObject( PrefsIcon );
  892.     return( 0 );
  893. }
  894.  
  895. /* This function write tooltype to icon */
  896. /* WriteToolType() (c) 1998 Paweî Marciniak <pmarciniak@lodz.home.pl>
  897.   Modify date  |  Version  |  Comment
  898. ---------------+-----------+------------------------------
  899. 20-10-98 8:19  |  1.0      |
  900. */
  901. LONG WriteToolType( STRPTR ToolTypeName, STRPTR ToolTypeArg, STRPTR IconName )
  902. {
  903.     struct DiskObject *Icon;
  904.     LONG i, j;
  905.     UBYTE **newtooltypes, **oldtooltypes;
  906.     UWORD sizettname, sizettarg, stringsize;
  907.     STRPTR ttstring, oldstring;
  908.  
  909.     if(!(Icon=GetDiskObjectNew( IconName )))
  910.         return(1000);
  911.  
  912.     sizettname=strlen(ToolTypeName);
  913.     sizettarg=strlen(ToolTypeArg);
  914.     stringsize=sizettname+sizettarg+2;
  915.  
  916.     if(!(ttstring=AllocVec( stringsize, MEMF_CLEAR )))
  917.     {
  918.         FreeDiskObject( Icon );
  919.         return(1001);
  920.     }
  921.     strcpy(ttstring, ToolTypeName );
  922.     strcat(ttstring, "=" );
  923.     strcat(ttstring, ToolTypeArg );
  924.  
  925.     for( i=0; Icon->do_ToolTypes[i]!=NULL; i++);
  926.  
  927.     for( j=0; j<i; j++ )
  928.     {
  929.         if(!strncmp( Icon->do_ToolTypes[j], ttstring, sizettname+1 ))
  930.         {
  931.             oldstring=Icon->do_ToolTypes[j];
  932.             Icon->do_ToolTypes[j]=ttstring;
  933.             PutDiskObject( IconName, Icon );
  934.             Icon->do_ToolTypes[j]=oldstring;
  935.             FreeVec( ttstring );
  936.             FreeDiskObject( Icon );
  937.             return( 0 );
  938.         }
  939.     }
  940.     if(!(newtooltypes=AllocVec( sizeof(newtooltypes)*(i+2), MEMF_CLEAR )))
  941.     {
  942.         FreeVec( ttstring );
  943.         FreeDiskObject( Icon );
  944.         return(1001);
  945.     }
  946.  
  947.     for( j=0; j<i; j++ )
  948.         newtooltypes[j]=Icon->do_ToolTypes[j];
  949.     newtooltypes[j]=ttstring;
  950.     oldtooltypes=Icon->do_ToolTypes;
  951.     Icon->do_ToolTypes=newtooltypes;
  952.     PutDiskObject( IconName, Icon );
  953.     Icon->do_ToolTypes=oldtooltypes;
  954.     FreeVec( ttstring );
  955.     FreeVec( newtooltypes );
  956.     FreeDiskObject( Icon );
  957.     return( 0 );
  958. }
  959.  
  960. /* Gîówna funkcja */
  961.  
  962. int main( int argc, char *argv[] )
  963. {
  964.   BOOL running=TRUE, busy=FALSE;
  965.   UBYTE text[100], undo[256];
  966.     ULONG TabOK=0, undounit;
  967.     STRPTR tempstr;
  968.   struct Requester busyreq;
  969.   struct RWMessage *msg;
  970.   struct List PortList;
  971.   struct List HistoryList;
  972.   struct WBArg *wba;
  973.   struct WBStartup *wbs;
  974.  
  975.     /* Start */
  976.  
  977.   NewList( &PortList );
  978.   NewList( &HistoryList );
  979.   InitSemaphore( &sem );
  980.     strcpy( path, MSG_TXT_PATH );
  981.     strcpy( header, MSG_TXT_HEADER );
  982.     strcpy( prtdev, MSG_TXT_PRTDEV );
  983.  
  984.   Forbid();
  985.   if (FindPort( RESETSERVERNAME ))
  986.   {
  987.     Permit();
  988.     printf("Program jest juû uruchomiony\n");
  989.     return( FALSE );
  990.   }
  991.   if (!(serverport=CreatePort( RESETSERVERNAME, 0L )))
  992.   {
  993.     Permit();
  994.     printf("Brak pamiëci na port\n");
  995.     return( FALSE );
  996.   }
  997.   Permit();
  998.   sigmsg = 1L << serverport->mp_SigBit;
  999.  
  1000.   if(!(OpenLibraries()))
  1001.   {
  1002.     ShutDown();
  1003.     return( FALSE );
  1004.   }
  1005.   
  1006.   if(!(SetupScreen()))
  1007.   {
  1008.     ShutDown();
  1009.     return( FALSE );
  1010.   }
  1011.  
  1012.     if(!argc)
  1013.     {
  1014.         wbs=(struct WBStartup *)argv;
  1015.         wba=&wbs->sm_ArgList[wbs->sm_NumArgs-1];
  1016.         ReadPrefs( path, header, wba->wa_Name );
  1017.     }
  1018.  
  1019.   if(!(OpenAPP_Display( 20, 20 )))
  1020.   {
  1021.     ShutDown();
  1022.     return( FALSE );
  1023.   }
  1024.  
  1025.   if(!(OpenMenu()))
  1026.   {
  1027.     ShutDown();
  1028.     return( FALSE );
  1029.   }
  1030.  
  1031.   if(!MakeGadget( &HistoryList, &PortList ))
  1032.   {
  1033.     ShutDown();
  1034.     return( FALSE );
  1035.   }
  1036.  
  1037.   if(!MakeGadget2( path, header, argc ))
  1038.   {
  1039.     ShutDown();
  1040.     return( FALSE );
  1041.   }
  1042.  
  1043.   if(!(MakeTab()))
  1044.   {
  1045.     ShutDown();
  1046.     return( FALSE );
  1047.   }
  1048.  
  1049.   SetFont( APP_Window->RPort, APP_Font );
  1050.   SetAPen( APP_Window->RPort, 0 );
  1051.   GT_SetGadgetAttrs( gad_text, APP_Window, 0, GTTX_Text, (ULONG)"Welcom to Reset.server emulator", TAG_DONE);
  1052.  
  1053.   AddGadget( APP_Window, gad_tab, -1 );
  1054.   AddGList( APP_Window, APP_GList, -1, -1, 0 );
  1055.   RefreshGList( gad_tab, APP_Window, 0, -1 );
  1056.  
  1057.     DrawGadsBox();
  1058.  
  1059.   do
  1060.   {
  1061.     sig=Wait( sigwin | sigmsg );
  1062.  
  1063.  
  1064.     while ( ReadIMsg( APP_Window ))
  1065.     {
  1066.       switch ( IClass )
  1067.       {
  1068.         case  IDCMP_REFRESHWINDOW:
  1069.           GT_BeginRefresh( APP_Window );
  1070.           GT_EndRefresh( APP_Window, TRUE );
  1071.         break;
  1072.  
  1073.         case  IDCMP_VANILLAKEY:
  1074.           switch( Code )
  1075.           {
  1076.               case 'u':
  1077.               break;
  1078.           }
  1079.         break;
  1080.  
  1081.         case  IDCMP_CLOSEWINDOW:
  1082.         if(EasyDialogBox( APP_Window, MSG_REQ_QUIT_TITLE, MSG_REQ_QUIT_TEXT, MSG_REQ_QUIT_BUTTON, 0 ))
  1083.                 {
  1084.             if( IsListEmpty( &PortList ) )
  1085.           {
  1086.             running=FALSE;
  1087.           }
  1088.           else
  1089.             if(TabOK)
  1090.             {
  1091.                 GadTabFunc( 0, TabOK );
  1092.                             GT_SetGadgetAttrs( gad_hist, APP_Window, 0, GTLV_Labels, -1, TAG_DONE);
  1093.                             GT_SetGadgetAttrs( gad_hist, APP_Window, 0, GTLV_Labels, &HistoryList, TAG_DONE);
  1094.                             GT_SetGadgetAttrs( gad_pname, APP_Window, 0, GTLV_Labels, -1, TAG_DONE);
  1095.                             GT_SetGadgetAttrs( gad_pname, APP_Window, 0, GTLV_Labels, &PortList, TAG_DONE);
  1096.                 SetGadgetAttrs( gad_tab, APP_Window, 0, TABS_Current, 0, TAG_DONE );
  1097.               TabOK=0;
  1098.             }
  1099.                         GT_SetGadgetAttrs( gad_text, APP_Window, 0, GTTX_Text, (ULONG)"First remove all ports", TAG_DONE);
  1100.                 }
  1101.         break; /* IDCMP_CLOSEWINDOW */
  1102.  
  1103.         case  IDCMP_GADGETUP:
  1104.           switch ( IObject->GadgetID )
  1105.           {
  1106.             case  GD_WARNING:
  1107.               SendWarning( &PortList );
  1108.               GT_SetGadgetAttrs( gad_text, APP_Window, 0, GTTX_Text, (ULONG)"Sending ResetWarning", TAG_DONE);
  1109.             break; /* GD_WARNING */
  1110.  
  1111.             case  GD_SAVE:
  1112.                             if(!argc)
  1113.                             {
  1114.                                 wbs=(struct WBStartup *)argv;
  1115.                                 wba=&wbs->sm_ArgList[0];
  1116. /* PATH */            strcpy( undo, path );
  1117.                   GT_GetGadgetAttrs( gad_path, APP_Window, 0, GTST_String, &tempstr, TAG_DONE);
  1118.                   strcpy( path, tempstr );
  1119.                                 if(WriteToolType( "PATH", path, wba->wa_Name ))
  1120.                                 {
  1121.                                     strcpy( path, undo );
  1122.                                 }
  1123. /* HEADER */        strcpy( undo, header );
  1124.                   GT_GetGadgetAttrs( gad_header, APP_Window, 0, GTST_String, &tempstr, TAG_DONE);
  1125.                   strcpy( header, tempstr );
  1126.                                 if(WriteToolType( "HEADER", header, wba->wa_Name ))
  1127.                                 {
  1128.                                     strcpy( header, undo );
  1129.                                 }
  1130. /* DEVICE */        strcpy( undo, prtdev );
  1131.                   GT_GetGadgetAttrs( gad_prtdev, APP_Window, 0, GTST_String, &tempstr, TAG_DONE);
  1132.                   strcpy( prtdev, tempstr );
  1133.                                 if(WriteToolType( "DEVICE", prtdev, wba->wa_Name ))
  1134.                                 {
  1135.                                     strcpy( prtdev, undo );
  1136.                                 }
  1137. /* UNIT */            undounit=prtunit;
  1138.                   GT_GetGadgetAttrs( gad_prtunit, APP_Window, 0, GTIN_Number, &prtunit, TAG_DONE);
  1139.                   sprintf( undo, "%ld", prtunit );
  1140.                                 if(WriteToolType( "UNIT", undo, wba->wa_Name ))
  1141.                                 {
  1142.                                     prtunit=undounit;
  1143.                                 }
  1144.                             }
  1145.             break; /* GD_SAVE */
  1146.  
  1147.             case  GD_USE:
  1148.               GT_GetGadgetAttrs( gad_path, APP_Window, 0, GTST_String, &tempstr, TAG_DONE);
  1149.               strcpy( path, tempstr );
  1150.               GT_GetGadgetAttrs( gad_header, APP_Window, 0, GTST_String, &tempstr, TAG_DONE);
  1151.               strcpy( header, tempstr );
  1152.               GT_GetGadgetAttrs( gad_prtdev, APP_Window, 0, GTST_String, &tempstr, TAG_DONE);
  1153.               strcpy( prtdev, tempstr );
  1154.               GT_GetGadgetAttrs( gad_prtunit, APP_Window, 0, GTIN_Number, &prtunit, TAG_DONE);
  1155.             break; /* GD_USE */
  1156.  
  1157.             case  GD_UNDO:
  1158.               GT_SetGadgetAttrs( gad_path, APP_Window, 0, GTST_String, path, TAG_DONE);
  1159.               GT_SetGadgetAttrs( gad_header, APP_Window, 0, GTST_String, header, TAG_DONE);
  1160.               GT_SetGadgetAttrs( gad_prtdev, APP_Window, 0, GTST_String, prtdev, TAG_DONE);
  1161.               GT_SetGadgetAttrs( gad_prtunit, APP_Window, 0, GTIN_Number, prtunit, TAG_DONE);
  1162.             break; /* GD_UNDO */
  1163.  
  1164.             case GD_TAB:
  1165.               switch( Code )
  1166.               {
  1167.                 case 0:
  1168.                                     GadTabFunc( Code, TabOK );
  1169.                                     GT_SetGadgetAttrs( gad_hist, APP_Window, 0, GTLV_Labels, -1, TAG_DONE);
  1170.                                     GT_SetGadgetAttrs( gad_hist, APP_Window, 0, GTLV_Labels, &HistoryList, TAG_DONE);
  1171.                                     GT_SetGadgetAttrs( gad_pname, APP_Window, 0, GTLV_Labels, -1, TAG_DONE);
  1172.                                     GT_SetGadgetAttrs( gad_pname, APP_Window, 0, GTLV_Labels, &PortList, TAG_DONE);
  1173.                   TabOK=0;
  1174.                 break;
  1175.                 
  1176.                 case 1:
  1177.                                     GadTabFunc( Code, TabOK );
  1178.                                     SetAPen( APP_Window->RPort, 1 );
  1179.                                     LineDraw(OffX, ComputeY( 90 )+OffY, (APP_Window->Width - (APP_Window->BorderRight)-1), ComputeY( 90 )+OffY );
  1180.                                     SetAPen( APP_Window->RPort, 2 );
  1181.                                     LineDraw(OffX, ComputeY( 90 )+OffY+1, (APP_Window->Width - (APP_Window->BorderRight)-1), ComputeY( 90 )+OffY+1 );
  1182.                                     SetAPen( APP_Window->RPort, 0 );
  1183.                   TabOK=1;
  1184.                 break;
  1185.  
  1186.                 case 2:
  1187.                                     GadTabFunc( Code, TabOK );
  1188.                                     DrawInfoText( MSG_TXT_AUTOR );
  1189.                   TabOK=2;
  1190.                 break;
  1191.  
  1192.                 case 3:
  1193.                                     GadTabFunc( Code, TabOK );
  1194.                                     DrawInfoText( MSG_TXT_ABOUT );
  1195.                   TabOK=3;
  1196.                 break;
  1197.               }
  1198.             break;
  1199.           }
  1200.         break; /* IDCMP_GADGETUP */
  1201.  
  1202.         case  IDCMP_MENUPICK:
  1203.           while( Code != MENUNULL )
  1204.           {
  1205.             switch( MENUNUM( Code ))
  1206.             {
  1207.               case TITLE_PROJECT:
  1208.                 switch( ITEMNUM( Code ))
  1209.                 {
  1210.                   case MENU_ABOUT:
  1211.                     busy=BusyStart( APP_Window, &busyreq );
  1212.                     EasyDialogBox( APP_Window, MSG_REQ_INFO_TITLE, MSG_REQ_INFO_TEXT, MSG_REQ_INFO_BUTTON, 0 );
  1213.                     if( busy ) BusyEnd( APP_Window, &busyreq );
  1214.                     Code=(ItemAddress( MenuStrip, Code ))->NextSelect;
  1215.                   break; /* MENU_ABOUT */
  1216.  
  1217.                   case MENU_QUIT:
  1218.                   if(EasyDialogBox( APP_Window, MSG_REQ_QUIT_TITLE, MSG_REQ_QUIT_TEXT, MSG_REQ_QUIT_BUTTON, 0 ))
  1219.                                     {
  1220.                                 if( IsListEmpty( &PortList ) )
  1221.                               {
  1222.                                    running=FALSE;
  1223.                               }
  1224.                               else
  1225.                             {
  1226.                                             if(TabOK)
  1227.                                 {
  1228.                                     GadTabFunc( 0, TabOK );
  1229.                                                 GT_SetGadgetAttrs( gad_hist, APP_Window, 0, GTLV_Labels, -1, TAG_DONE);
  1230.                                                 GT_SetGadgetAttrs( gad_hist, APP_Window, 0, GTLV_Labels, &HistoryList, TAG_DONE);
  1231.                                                 GT_SetGadgetAttrs( gad_pname, APP_Window, 0, GTLV_Labels, -1, TAG_DONE);
  1232.                                                 GT_SetGadgetAttrs( gad_pname, APP_Window, 0, GTLV_Labels, &PortList, TAG_DONE);
  1233.                                         SetGadgetAttrs( gad_tab, APP_Window, 0, TABS_Current, 0, TAG_DONE );
  1234.                                      TabOK=0;
  1235.                                 }
  1236.                                             GT_SetGadgetAttrs( gad_text, APP_Window, 0, GTTX_Text, (ULONG)"First remove all ports", TAG_DONE);
  1237.                                         }
  1238.                                     }
  1239.                     Code=(ItemAddress( MenuStrip, Code ))->NextSelect;
  1240.                   break;/* MENU_QUIT */
  1241.                 }
  1242.               break;/* TITLE_PROJECT */
  1243.  
  1244.               case TITLE_EDIT:
  1245.                 switch( ITEMNUM( Code ))
  1246.                 {
  1247.                   case MENU_SAVEHIST:
  1248.                     if(!(WriteHistory( path, header, &HistoryList )))
  1249.                     {
  1250.                       busy=BusyStart( APP_Window, &busyreq );
  1251.                       EasyDialogBox( APP_Window, MSG_REQ_ERR_TITLE, MSG_REQ_ERR_WRITE, MSG_REQ_ERR_BUTTON, path );
  1252.                       if( busy ) BusyEnd( APP_Window, &busyreq );
  1253.                     }
  1254.                     Code=(ItemAddress( MenuStrip, Code ))->NextSelect;
  1255.                   break; /* MENU_SAVEHIS */
  1256.  
  1257.                   case MENU_CLEARHIST:
  1258.                     if(!TabOK) GT_SetGadgetAttrs( gad_hist, APP_Window, 0, GTLV_Labels, -1, TAG_DONE);
  1259.                     RemHistory( &HistoryList );
  1260.                     if(!TabOK) GT_SetGadgetAttrs( gad_hist, APP_Window, 0, GTLV_Labels, &HistoryList, TAG_DONE);
  1261.                     Code=(ItemAddress( MenuStrip, Code ))->NextSelect;
  1262.                   break; /* MENU_CLEARHIS */
  1263.  
  1264.                   case MENU_PRINT:
  1265.                       busy=BusyStart( APP_Window, &busyreq );
  1266.                       if(PrintHistory( prtdev, prtunit, &HistoryList ))
  1267.                           EasyDialogBox( APP_Window, MSG_REQ_ERR_TITLE, MSG_REQ_ERR_PRINT, MSG_REQ_ERR_BUTTON, 0 );
  1268.                       if( busy ) BusyEnd( APP_Window, &busyreq );
  1269.                       
  1270.                     Code=(ItemAddress( MenuStrip, Code ))->NextSelect;
  1271.                   break; /* MENU_PRINT */
  1272.                 }
  1273.               break; /* TITLE_EDIT */
  1274.             }
  1275.           }
  1276.         break; /* IDCMP_MENUPICK */
  1277.  
  1278.         default:
  1279.         break;
  1280.       }
  1281.     }
  1282.  
  1283.     while( msg=(struct RWMessage *)GetMsg( serverport ))
  1284.     {
  1285.       switch( msg->rwm_Message.mn_Node.ln_Type )
  1286.       {
  1287.         case  NT_REPLYMSG:
  1288.           switch( msg->rwm_MsgType )
  1289.           {
  1290.                 case RWM_RESETWARNING:
  1291.               FreeVec( msg );
  1292.             break;
  1293.           }
  1294.         break;
  1295.  
  1296.         case  NT_MESSAGE:
  1297.           switch( msg->rwm_MsgType )
  1298.           {
  1299.             case  RWM_ADDPORT:
  1300.               MessageFunc( text, MSG_TXT_ADDPORT, RWM_ADDPORT, msg, &PortList, &HistoryList, TabOK );
  1301.             break;
  1302.  
  1303.             case  RWM_REMPORT:
  1304.               MessageFunc( text, MSG_TXT_REMPORT, RWM_REMPORT, msg, &PortList, &HistoryList, TabOK );
  1305.             break;
  1306.  
  1307.             case  RWM_DONE:
  1308.               MessageFunc( text, MSG_TXT_DONE, RWM_DONE, msg, &PortList, &HistoryList, TabOK );
  1309.             break;
  1310.  
  1311.             default:
  1312.             break;
  1313.           }
  1314.         ReplyMsg((struct Message *)msg);
  1315.         break;
  1316.         
  1317.         default:
  1318.         break;
  1319.  
  1320.       }
  1321.     } /* while reset serverport */
  1322.   } while ( running );
  1323.  
  1324.   ShutDown();
  1325.   RemHistory( &HistoryList );
  1326.   return( TRUE );
  1327. }
  1328.